/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 06 - 03
 * Time: 12:04
 */
interface USB{
    void openDevice();
    void closeDevice();
}

class KeyBoard implements USB{
    @Override
    public void openDevice(){
        System.out.println("打开键盘");
    }

    @Override
    public void closeDevice() {
        System.out.println("关闭键盘");
    }

    public void inPut() {
        System.out.println("键盘输入");
    }
}

class Computer{
    public void useDevice(USB usb){//向上转型
        usb.openDevice();//动态绑定
        if(usb instanceof KeyBoard){
            KeyBoard keyBoard =(KeyBoard)usb;//向下转型
            keyBoard.inPut();
        }
        usb.closeDevice();//动态绑定
    }

    public static void main(String[] args){
        Computer computer = new Computer();
        computer.useDevice(new KeyBoard());//使用键盘
    }
}
